#include "EditorCore/Actions/Action.h"
#include "Common/Exceptions/ProductException.h"

using namespace cmn;

namespace editor_core {

	Action::Action() :
		m_isDone( false )
	{}

	bool Action::Do() {
		if( !m_isDone ) {
			m_isDone = Commit();
			return m_isDone;
		}
		return false;
	}

	void Action::Undo() {
		if( GetType() != ActionType::Undoable )
			throw ProductException( "You cannot undo not undoable Action" );
		if( m_isDone ) {
			Rollback();
			m_isDone = false;
		}
	}

	void Action::Redo() {
		if( GetType() != ActionType::Undoable )
			throw ProductException( "You cannot redo not undoable Action" );
		if( !m_isDone ) {
			Recommit();
			m_isDone = true;
		}
	}
}
